package com.jiakai.cashinterfacemucon.controller;


import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.jiakai.cashinterfacemucon.dto.*;
import com.jiakai.cashinterfacemucon.model.LogWithBLOBs;
import com.jiakai.cashinterfacemucon.service.LogService;
import com.jiakai.cashinterfacemucon.service.SilverFamilyService;
import com.jiakai.cashinterfacemucon.utils.DateUtils;
import com.jiakai.cashinterfacemucon.utils.EmptyUtils;
import com.jiakai.cashinterfacemucon.utils.EncryptionUtils;
import com.jiakai.cashinterfacemucon.vo.OrderChangeVO;
import com.jiakai.cashinterfacemucon.vo.OrderOccupiesVO;
import com.lishunyi.result.VO.ResultVO;
import com.lishunyi.result.utils.ResultUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

@CrossOrigin
@RestController
@RequestMapping("/cashinterface")
public class SilverFamilyController {
    // 数据库类日志服务
    @Autowired
    private LogService logService;
    // 银科相关服务
    @Autowired
    private SilverFamilyService silverFamilyService;
    /**
     * 不传参,执行产品拉取,返回成功更新产品数与新增产品数的和
     * @return
     */
    @RequestMapping("/pull")
    public ResultVO pullProducts(){
        GetProductsDto dto = new GetProductsDto();
        dto.setDate(DateUtils.formatToDate(new Date()));
        dto.setType("00");
        dto.setParkCode("clota");
        Integer intReturn = silverFamilyService.getProducts(dto);
        if (intReturn == null){
            return ResultUtils.error(999,"产品拉取失败");
        }
        return ResultUtils.success(intReturn);
    }

    // 银科对接OrderOccupies 占用
    @PostMapping("/order/occupies")
    public ResultVO orderOccupies(@RequestBody OrderOccupiesVO vo){
        System.out.println(vo);

        ResultVO resultVO = silverFamilyService.orderOccupies(vo);

        return resultVO;
    }

    // 银科对接OrderRelease 释放
    @PostMapping("/order/release")
    public ResultVO orderRelease(String orderNo){

        ResultVO resultVO = silverFamilyService.orderRelease(orderNo);
        return resultVO;
    }

    // 银科对接OrderFinish 完成
    @PostMapping("/order/finish")
    public ResultVO orderFinish(String orderNo){
        ResultVO resultVO = silverFamilyService.orderFinish(orderNo);
        return resultVO;
    }

    // 银科对接ChangeOrderEdit 退票
    @PostMapping("/order/change")
    public ResultVO orderChange(@RequestBody OrderChangeVO vo){
        ResultVO resultVO = silverFamilyService.orderChange(vo);
        return resultVO;
    }

    // 银科对接NoticeOrder 回调
    @RequestMapping("/order/notice")
    public String orderNotice(String OrderID, String ECode, Integer OrderNum, String NoticeType, String signature){
        // 消息体 = OrderID + ECode + OrderNum + NoticeType 加密呢?

        ResultDto resultDto = silverFamilyService.orderNotice(OrderID,ECode,OrderNum,NoticeType,signature);
        Gson gson = new Gson();
        return gson.toJson(resultDto);
    }

    @RequestMapping("/hello")
    public String hello(){
        return "hello";
    }
}
